package cn.initcap.algorithm.lambda;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * @author initcap
 * @date Created in 12/2/18 9:24 AM.
 */
public class DateSort {

    public static void main(String[] args) {
        Date date = new Date();
        Date date1 = new Date();
        date.setTime(1311111111111L);
        date1.setTime(1322222222222L);
        Test test = new Test();
        test.setDate(date);
        Test test1 = new Test();
        test1.setDate(date1);
        List<Test> list = new ArrayList<>(2);
        list.add(test);
        list.add(test1);
        Collections.sort(list, Comparator.comparing(Test::getDate).reversed());
        System.out.println(list);
    }

    static class Test {
        private Date date;

        public Date getDate() {
            return date;
        }

        public void setDate(Date date) {
            this.date = date;
        }

        @Override
        public String toString() {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            return "Test{" +
                    "date=" + sdf.format(date) +
                    '}';
        }
    }

}
